package com.gzgs.controller;


import com.github.pagehelper.PageInfo;
import com.gzgs.domain.Orders;
import com.gzgs.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 订单前端控制器
 */
@Controller
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 查询所有的订单信息--分页
     * @param page
     * @param size
     * @return
     * @throws Exception
     */
    @RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue = "1") Integer page, @RequestParam(name = "size", required = true, defaultValue = "4") Integer size) throws Exception {
        ModelAndView mv = new ModelAndView();
        System.out.println("执行1");
        List<Orders> ordersList = ordersService.findAll(page, size);

        //PageInfo就是一个分页Bean
        PageInfo pageInfo=new PageInfo(ordersList);
        mv.addObject("pageInfo",pageInfo);
        System.out.println("执行2");
        mv.setViewName("orders-page-list");
        System.out.println("执行12");
        System.out.println(page+"======="+size);
        return mv;
    }


    /**
     *查看订单详情
     */
    @RequestMapping("/findById.do")
    public ModelAndView findById(String id){
        ModelAndView mv=new ModelAndView();
        Orders orders=ordersService.findById(id);
        mv.setViewName("orders-show");
        mv.addObject("orders",orders);
        return mv;
    }
}
